package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class BrrowOperation implements IOPeration{
    @Override
    public void work(BookList bookList) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("借阅图书");

        System.out.println("输入你要借阅的图书：");
        String name = scanner.nextLine();

        int currentSize = bookList.getUsedSize();
        for (int i = 0; i < currentSize; i++) {
            Book book = bookList.getBook(i);
            //有 && 没被借出
           if(book.getName().equals(name)&& !book.isBorrowed()){
            book.setBorrowed(true);
               System.out.println("借阅成功");
               return;
           }
        }
        System.out.println("没有你要借阅的图书");
    }
}
